package com.dhc.appbusinessfrm.network.callback;

import com.dhc.appbusinessfrm.task.TaskLocker;

import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
 * Created by xy on 2015/6/23.
 */
public class NetTaskCallback<T> implements Callback<T> {

    private TaskLocker<T> locker = null;

    public NetTaskCallback(TaskLocker<T> locker) {
        this.locker = locker;
    }

    @Override
    public void success(T t, Response response) {
        if (locker != null) {
            synchronized (locker) {
                locker.setResult(t);
                locker.notifyAll();
            }
        }
    }

    @Override
    public void failure(RetrofitError error) {
        if (locker != null) {
            synchronized (locker) {
                locker.notifyAll();
            }
        }
    }

}
